package com.bnlr.lrparking.appui.mine.vip;

import android.app.Dialog;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bnlr.lrparking.R;
import com.bnlr.lrparking.base.BaseActivity;
import com.bnlr.lrparking.app.AppConfig;

import jp.wasabeef.glide.transformations.CropCircleTransformation;

/**
 * Created by hp on 2017/9/1.
 * 会员类别
 */

public class VipTypeActivity extends BaseActivity {


    private RelativeLayout vip_rely1,vip_rely2,vip_rely3,vip_rely4,
            vip_rely5,vip_rely6,vip_rely7,vip_rely8;
    private ImageView img_head_portrait,vip_back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_viptype);
        initView();
    }

    private void initView(){
        vip_back=(ImageView)findViewById(R.id.vip_back);
        vip_rely1=(RelativeLayout) findViewById(R.id.vip_rely1);
        vip_rely2=(RelativeLayout) findViewById(R.id.vip_rely2);
        vip_rely3=(RelativeLayout) findViewById(R.id.vip_rely3);
        vip_rely4=(RelativeLayout) findViewById(R.id.vip_rely4);
        vip_rely5=(RelativeLayout) findViewById(R.id.vip_rely5);
        vip_rely6=(RelativeLayout) findViewById(R.id.vip_rely6);
        vip_rely7=(RelativeLayout) findViewById(R.id.vip_rely7);
        vip_rely8=(RelativeLayout) findViewById(R.id.vip_rely8);
        img_head_portrait=(ImageView)findViewById(R.id.img_head_portrait);
        vip_rely1.setOnClickListener(this);
        vip_rely2.setOnClickListener(this);
        vip_rely3.setOnClickListener(this);
        vip_rely4.setOnClickListener(this);
        vip_rely5.setOnClickListener(this);
        vip_rely6.setOnClickListener(this);
        vip_rely7.setOnClickListener(this);
        vip_rely8.setOnClickListener(this);
        vip_back.setOnClickListener(this);
        if (AppConfig.getInstance().getBoolean("isLogin",false)) {
            Glide.with(this)
                    .load(AppConfig.getInstance().getString("photo", ""))
                    .bitmapTransform(new CropCircleTransformation(this))
                    .placeholder(R.mipmap.personal_head)
                    .error(R.mipmap.personal_head)
                    .into(img_head_portrait);
        } else {
            Glide.with(this)
                    .load(R.mipmap.personal_head)
                    .bitmapTransform(new CropCircleTransformation(this))
                    .into(img_head_portrait);
        }

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.vip_rely1:
                bottomDialog("虚拟车位主","",getResources().getString(R.string.strIntroduce1));
                break;
            case R.id.vip_rely2:
                bottomDialog("真实车位主",getResources().getString(R.string.strTitle2),getResources().getString(R.string.strIntroduce2));
                break;
            case R.id.vip_rely3:
                bottomDialog("付费会员",getResources().getString(R.string.strTitle3),getResources().getString(R.string.strIntroduce3));
                break;
            case R.id.vip_rely4:
                bottomDialog("业主",getResources().getString(R.string.strTitle4),getResources().getString(R.string.strIntroduce4));
                break;
            case R.id.vip_rely5:
                bottomDialog("普通会员",getResources().getString(R.string.strTitle5),getResources().getString(R.string.strIntroduce5));
                break;
            case R.id.vip_rely6:
                bottomDialog("车库厂方",getResources().getString(R.string.strTitle6),getResources().getString(R.string.strIntroduce6));
                break;
            case R.id.vip_rely7:
                bottomDialog("汽车厂方",getResources().getString(R.string.strTitle7),getResources().getString(R.string.strIntroduce7));
                break;
            case R.id.vip_rely8:
                bottomDialog("资本方",getResources().getString(R.string.strTitle8),getResources().getString(R.string.strIntroduce8));
                break;
            case R.id.vip_back:
                finish();
                break;


        }
    }

    private void bottomDialog(String vipStrType,String strTitle,String strIntroduce){
        final Dialog mCameraDialog = new Dialog(VipTypeActivity.this, R.style.my_dialog);
        LinearLayout root = (LinearLayout) LayoutInflater.from(VipTypeActivity.this).inflate(
                R.layout.vip_bottom_dialog, null);
        TextView tv_viptype=(TextView)root.findViewById(R.id.tv_viptype);
        TextView vip_title=(TextView)root.findViewById(R.id.vip_title);
        RelativeLayout rely_close=(RelativeLayout)root.findViewById(R.id.rely_close);
        TextView tv_vipIntroduce=(TextView)root.findViewById(R.id.tv_vipIntroduce);
        tv_viptype.setText(vipStrType);
        vip_title.setText(strTitle);
        tv_vipIntroduce.setText(strIntroduce);
        rely_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCameraDialog.dismiss();
            }
        });
        mCameraDialog.setContentView(root);
        mCameraDialog.setCanceledOnTouchOutside(true);
        Window dialogWindow = mCameraDialog.getWindow();
        dialogWindow.setGravity(Gravity.BOTTOM);
        dialogWindow.setWindowAnimations(R.style.dialogstyle); // 添加动画
        WindowManager.LayoutParams lp = dialogWindow.getAttributes(); // 获取对话框当前的参数值
        lp.x = 0; // 新位置X坐标
        lp.y = -20; // 新位置Y坐标
        lp.width = (int) getResources().getDisplayMetrics().widthPixels; // 宽度
        root.measure(0, 0);
        lp.height = root.getMeasuredHeight();
        lp.alpha = 9f; // 透明度
        dialogWindow.setAttributes(lp);
        mCameraDialog.show();
    }
}
